package com.lottery.im.module.contact.presenter;

import android.app.Activity;
import com.lottery.im.base.BaseFragmentPresenter;
import com.lottery.im.module.contact.view.BlackListView;
import com.tencent.imsdk.TIMFriendshipManager;
import com.tencent.imsdk.TIMUserProfile;
import com.tencent.imsdk.TIMValueCallBack;
import com.tencent.imsdk.ext.sns.TIMFriendshipManagerExt;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.FragmentEvent;
import java.util.List;

public class BlackListPresenter extends BaseFragmentPresenter<BlackListView> {

  public BlackListPresenter(Activity activity,
      BlackListView iView,
      LifecycleProvider<FragmentEvent> provider) {
    super(activity, iView, provider);
  }

  /**
   * 获取黑名单列表
   */
  public void getBlackList() {

    TIMFriendshipManagerExt.getInstance().getBlackList(new TIMValueCallBack<List<String>>() {
      @Override
      public void onError(int i, String s) {
        if (null == iView) return;
        iView.showToast("获取黑名单失败～");
      }

      @Override
      public void onSuccess(List<String> ids) {

        if (null == ids || ids.size() == 0) {
          iView.getListSuc(null);
          return;
        }

        TIMFriendshipManager.getInstance().getUsersProfile(ids,
            new TIMValueCallBack<List<TIMUserProfile>>() {
              @Override public void onError(int i, String s) {
                if (null == iView) return;
                iView.showToast("获取黑名单失败～");
              }

              @Override public void onSuccess(List<TIMUserProfile> timUserProfiles) {
                if (null == iView) return;
                iView.getListSuc(timUserProfiles);
              }
            });
      }
    });
  }
}
